/*
 * rs485.h
 *
 *  Created on: Dec 9, 2011
 *      Author: kylintse
 */

#ifndef RS485_H_
#define RS485_H_

#include <QtCore>
#include "kthread.h"
#include "DeviceProtocol.h"

class rs485
{
public:
	rs485(const QString& devNode);
	virtual ~rs485();

public:
	bool init();

	int send(char* data,int size);
	int recv(char* data,int size,int timeout);

private:
	QString m_devNode;
	int m_bitrate;
	int m_databits;
	int m_stopbits;
	int m_parity;
	int m_fd;
};

class rs485Test;

class rs485TestThread : public kthread
{
public:
	rs485TestThread(rs485Test* test,QObject* parent=0);
	~rs485TestThread();

protected:
	virtual void run();

private:
	rs485Test* m_test;
};

class rs485Test : public DeviceProtocol
{
public:
	rs485Test(quint32 id,const QString& devNode);
	virtual ~rs485Test();

public:
	virtual bool start();
	virtual void stop();

	virtual void recycle();

	void doTest();

private:
	rs485* m_port;
	rs485TestThread* m_thread;

	char m_recvBuf[256];
};

#endif /* RS485_H_ */
